#coding:utf8
'''
Created on 2017/2/23
4:03
@author: Moon
qq : 550302989
'''
import datetime
import Feature

class TaskCommentManage(object):

    def __init__(self):
        # 用反射获取类方法
        # self.__Feature = __import__("Feature")
        # self.__feature = getattr(self.__Feature,"Feature")()
        self.__feature = Feature.Feature()

    # 根据任务id 查找此任务最新评伦楼层数
    def findTaskCommentFloor(self,taskid):
        sql = "select max(floor) from taskcomment where taskid='{taskid}'".format(taskid=taskid)
        return self.__feature.findFeatureOne(sql)

    # 添加评论（所有管理员/此任务的会员）
    def addComment(self,comment_info):
        sql = "insert into taskcomment(taskid,floor,commentmanid,content,taskcomment.time) values('{taskid}','{floor}','{commentmanid}','{content}','{time}')".format(
            taskid=comment_info['taskid'],floor=comment_info['floor'],commentmanid=comment_info['commentmanid'],content=comment_info['content'],time=datetime.datetime.now().strftime('%Y-%m-%d')
        )
        return self.__feature.dataCommitFeature(sql)

    # 查看指定任务的所有评论（所有管理员/此任务的会员）
    def findComment(self,taskid):
        sql = "select id,taskid,floor,commentmanid,content,taskcomment.time from taskcomment where taskid='{taskid}'".format(taskid=taskid)
        return self.__feature.findFeatureAll(sql)

    # 修改评论（至高权限）
    def updateComment(self,commentid,content):
        sql = "update taskcomment set content='{content}' where id='{commentid}'".format(content=content,commentid=commentid)
        return self.__feature.dataCommitFeature(sql)

    # 删除评论（至高权限）
    def deleteComment(self,commentid):
        sql = "delete from taskcomment where id='{commentid}'".format(commentid=commentid)
        return self.__feature.dataCommitFeature(sql)

    # 添加回复评论（所有管理员/此任务的会员）
    def addReply(self,reply_info):
        sql = "insert into commentreply(taskid,commentid,replymanid,content,time) " \
              "values(taskid='{taskid}',commentid='{commentid}',replymanid='{replymanid}',content='{content}',time='time')".format(
            taskid=reply_info['taskid'],commentid=reply_info['commentid'],replymanid=reply_info['replymanid'],content=reply_info['content'],time=datetime.datetime.now().strftime('%Y-%m-%d')
        )
        return self.__feature.dataCommitFeature(sql)

    # 根据评论id 查看回复评论（所有管理员/此任务的会员）
    def findReply(self,commentid):
        sql = "select id,taskid,commentid,replymanid,connent,time from commentreply where commentid='{commentid}'".format(commentid=commentid)
        return self.__feature.findFeatureOne(sql)

    # 修改回复评论（至高权限）
    def updateReply(self,id,content):
        sql = "update commentreply set content='{content}' where id='{id}'".format(contetn=content,id=id)
        return self.__feature.dataCommitFeature(sql)

    # 删除回复评论（至高权限）
    def deleteReply(self,id):
        sql = "delete from commentreply where id='{id}'".format(id=id)
        return self.__feature.dataCommitFeature(sql)
